package com.myproject.thread.pool;

import java.util.concurrent.*;

/*
* 线程池中任务抛出异常的情况
* */
public class Test11 {

    private static ThreadPoolExecutor executor = new ThreadPoolExecutor(10, 10,
            0L, TimeUnit.MILLISECONDS,
            new LinkedBlockingQueue<Runnable>());
    public static void main(String[] args) {

        ThreadPoolExecutor executor = new ThreadPoolExecutor(10, 10,
                0L, TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<Runnable>());
        for (int i = 0; i < 20; i++) {
            executor.execute(new Task());
        }

    }

    static class Task implements Runnable{

        @Override
        public void run() {
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            String name = Thread.currentThread().getName();
            String[] split = name.split("-");
            String s = split[split.length - 1];
            Integer integer = Integer.valueOf(s);
            if (integer%2==0){
                throw new RuntimeException("偶数报错");
            }
            System.out.println(Thread.currentThread().getName());
        }
    }

}
